/**
 * @param {string[]} strs
 * @return {string}
 * 输入：strs = ["flower","flow","flight"]
输出："fl"
 */
var longestCommonPrefix = function (strs) {
  if (strs.length == 1) return strs[0]
  strs.sort((a, b) => a.length - b.length)
  let start = 0,
    shortStr = strs[0]

  while (start < shortStr.length) {
    for (let i = 1; i < strs.length; i++) {
      if(strs[i][start]!=shortStr[start])return shortStr.slice(0,start)
    }
    start++
  }

  return shortStr(0,start)
}

console.log(longestCommonPrefix(["dog","racecar","car"]));
